package bueu.bexl;

import bueu.bexl.utils.Interval;

public class IntervalExpr extends BinayExpr {

	private final boolean lowerClosed;
	private final boolean upperClosed;

	public IntervalExpr(final BexlExpr lower, final boolean lowerClosed, BexlExpr upper,
			final boolean upperClosed) {
		super(lower, upper);
		this.lowerClosed = lowerClosed;
		this.upperClosed = upperClosed;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected final Object evaluate(Object value1, Object value2) {
		if (value1 instanceof Comparable && value2 instanceof Comparable) {
			return new Interval<Object>((Comparable<Object>) value1,
					this.lowerClosed, (Comparable<Object>) value2, this.upperClosed);			
		}
		
		throw new RuntimeException("TODO");
	}
	
	@Override
	public final String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(this.lowerClosed? '[': '(');
		sb.append(getExpr1());
		sb.append(", ");
		sb.append(getExpr2());
		sb.append(this.upperClosed? ']': ')');
		
		return sb.toString();
	}
}
